package com.artnology.independence.views.jung;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.ItemSelectable;
import java.awt.event.InputEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import com.artnology.independence.views.DependencyViewer;

import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.control.TranslatingGraphMousePlugin;

public class SpecialModalGraphMouse<V,E> extends AbstractModalGraphMouse
implements ModalGraphMouse, ItemSelectable {
	
 
/**
 * create an instance with default values
 *
 */
public SpecialModalGraphMouse(DependencyViewer myViewer) {
    this(1.1f, 1/1.1f, myViewer);
	

}
 
/**
 * create an instance with passed values
 * @param in override value for scale in
 * @param out override value for scale out
 */
public SpecialModalGraphMouse(float in, float out, DependencyViewer myViewer) {
    super(in,out);
    loadPlugins(myViewer);
    setModeKeyListener(new ModeKeyAdapter(this));
}
 
/**
 * create the plugins, and load the plugins for TRANSFORMING mode
 *
 */

protected void loadPlugins(DependencyViewer myViewer) {
    pickingPlugin = new PickingGraphMousePlugin<V,E>(myViewer);
   // animatedPickingPlugin = new AnimatedPickingGraphMousePlugin<V,E>();
    translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON2_MASK);
    scalingPlugin = new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, in, out);
    add(scalingPlugin);
    add(translatingPlugin);
    add(pickingPlugin);

    
    setMode(Mode.TRANSFORMING);
}
 
public static class ModeKeyAdapter extends KeyAdapter {
    private char t = 't';
    private char p = 'p';
    protected ModalGraphMouse graphMouse;

    public ModeKeyAdapter(ModalGraphMouse graphMouse) {
        this.graphMouse = graphMouse;
    }

    public ModeKeyAdapter(char t, char p, ModalGraphMouse graphMouse) {
        this.t = t;
        this.p = p;
        this.graphMouse = graphMouse;
    }
     
    @Override
    public void keyTyped(KeyEvent event) {
        char keyChar = event.getKeyChar();
        if(keyChar == t) {
            ((Component)event.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            graphMouse.setMode(Mode.TRANSFORMING);
        } else if(keyChar == p) {
            ((Component)event.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            graphMouse.setMode(Mode.PICKING);
        }
    }
}

@Override
protected void loadPlugins() {
}
}
